<template>
  <div class="app-container">
    <basic-table
      :table-title="tableTitle"
      :data-source="dataSource"
      :button-group="buttonGroup"
      :search-form="searchForm"
      :model-type="'allReport'"
      :multiple-table="false"
      :reload="reload"
      @closeReload="closeReload"
      >
     <template v-slot:UsageRate="scope">
        <div style="color: #E6A23C">
        {{ scope.row.UsageRate }}
        </div>
      </template>
    </basic-table>
  </div>
</template>
<script>
import { getTotalUserForms } from '@/api/report'
import BasicTable from '@/components/BasicTable/index.vue'
export default {
  name: 'All',
  components: { BasicTable },
  data() {
    return {
      flag:false,
      reload: false,
      tableData:[],
      dataSource: () => getTotalUserForms,
      tableTitle: [
      {
          label: '公司数量',
          value: 'UserCompanyNum',
          show: true,
          type: 'text',
        },
        
        {
          label: '用户数量',
          value: 'UserNum',
          show: true,
          type: 'text',
        },
        {
          label: '登录用户数',
          value: 'LoginUserNum',
          show: true,
          type: 'text'
        },
        {
          label: '使用率',
          value: 'UsageRate',
          show: true,
          type: 'slot',
          slot: 'UsageRate'
        },
        {
          label: '登录次数',
          value: 'LoginNum',
          show: true,
          type: 'text',
        },
        {
          label: '搜索企业次数',
          value: 'SearchCompanyNum',
          show: true,
          type: 'text'
        },
       
        {
          label: '查看企业详情次数',
          value: 'CompanyInfoNum',
          show: true,
          type: 'text'
        },
        {
          label: '解锁企业次数',
          value: 'CompanyUnlockNum',
          show: true,
          type: 'text'
        },
        {
          label: '添加客户数',
          value: 'AddClientNum',
          show: true,
          type: 'text'
        },
      ],
      searchForm: {
        expend: true,
        title: '',
        fields: [
        {
            show: true,
            type: 'datetimerange',
            label: '统计时间',
            labelShow: true,
            name: 'time'
          },
        ]
      },
      buttonGroup: {},
    }
  },
  created(){
    this.getPageList()
  },
  methods: {
    getPageList() {
      getTotalUserForms().then((res)=>{
        this.flag = true
        console.log(res)
        let keyToSkip = 'UsageRate'
        const newObject = {}
        const newObject2 = []        
        for (const key in res.data) {
        if (res.data.hasOwnProperty(key) && !keyToSkip.includes(key)) {
          newObject[key] = res.data[key];
        }
        }
        this.tableTitle.forEach((item)=>{
          if(item.value !== keyToSkip){
            newObject2.push(item)
          }
        })
        console.log('res.data', newObject)
        console.log('newObject23', newObject2)
        for(var key in newObject){
              this.tableData.push({value: res.data[key]});
          }
          // var tableData2 = []
         
              //   for(let j = 0; j<this.tableData.length; j++){
              //     for(let i = 0; i<newObject2.length; i++){
              //   this.tableData[j]

              // }
              // }
        console.log('this.tableData', this.tableData)
      })
     
    },
    closeReload(val) {
      this.reload = val
    },
  }
}
</script>

<style scoped></style>
